package servletlearn.readresource;

import servletlearn.readresource.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Properties;

public class FileReadServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = getServletContext().getResource("WEB-INF/classes/db.properties").getPath();
        OutputStream outputStream = response.getOutputStream();
        Properties prop = new Properties();
        prop.load(new FileInputStream(path));
        String url = prop.getProperty("url");

        UserDao userDao = new UserDao();


        outputStream.write((url + userDao.test()).getBytes());
        outputStream.flush();
        outputStream.close();

    }
}
